import nltk
import csv
import re
import math
import pickle
import operator
class Features(object):
    def __init__(self, trainfileName, testfileName,  trainlemmafile, testlemmafile, freqFile,POSdata, posStopWords,collocFile ):
        stopfile=open(posStopWords)        
        self.posStopWords=[word_pos.upper().strip() for word_pos in stopfile.readlines()]
        self.trainfileName=trainfileName
        self.testfileName=testfileName
        self.testmap=pickle.load(open( testlemmafile, "rb" ))
        self.trainmap=pickle.load(open( trainlemmafile, "rb" ))
        self.posmap=pickle.load(open(POSdata,"rb"))
        self.trainmap=dict(self.testmap.items() + self.trainmap.items())
        self.testDepMap=pickle.load(open("../../data/testDepRel.p","rb"))
        self.trainDepMap=pickle.load(open("../../data/trainDepRel.p","rb"))
        self.trainDepmap=dict(self.testDepMap.items() + self.trainDepMap.items())
        self.fullDepMap=pickle.load(open("../../data/FullDepRelFreq.p","rb"))
        self.uniqueFeaturesList=pickle.load(open("../../data/uniqueWordFeatures.p","rb"))
       # self.newtrainmap=self.trainmap
        self.colList=pickle.load(open(collocFile,'rb'))
        self.freqList=[]
        for line in open(freqFile).readlines():
            self.freqList.append(line.strip())
        self.headings=["AIM", "METHOD", "RESULTS", "CONCLUSION"]
                   
 
    def getFeaturesForLineTest(self, stopWordFile,outFile,nfeature):        
        stopFile = open(stopWordFile)
        wordFeatures=self.freqList[:nfeature]
        stopWords = [line.strip().upper() for line in stopFile.readlines()]
        stopFile.close()
        resultFile = open(outFile, 'w')        
        spamReader = csv.reader(open(self.testfileName, 'rb'), delimiter=',')       
        count = 0
        heading = ""
        sentList=[]
        structBool=False
        temp_heading=""
        prevClass="6"
        thisClass="6"
        max=0
        maxLabel="other"
        for line in spamReader:
            print line            
            count += 1
            resultText = ""
            wordCount = 0   
            prevClass=thisClass
            if max < line[4]:
                max=line[4]
                maxLabel=line[0]     
            if line[2]=="1" and len(sentList)>0:
                #print line[3], structBool
                indList=[]
                max=0
                maxLabel="other"
                if not structBool:
                    #print "Entered and checking!"
                    for i in range(1,5):
                        indList.append(math.ceil(float(len(sentList)*i/4)))
                for i in range(0,len(sentList)):
                    (feaList,thisSentFeatures)=sentList[i]
                    sentNorm=float(i+1)/len(sentList)
                    revInd=len(sentList)-i 
                    print feaList
                    if not structBool:
                        heading=self.getDynamicHeading(i,indList,sentList)
                        #print heading
                    else:
                        heading=feaList[1]                                                                    
                    resultFile.write(",".join(thisSentFeatures)+","+str(sentNorm)+","+str(revInd)+","+feaList[0]+","+heading+"\n")
                    #resultFile.write(str(sentNorm)+","+sentList[i][0]+","+heading+"\n")
                sentList=[]                                   
            if (count > 1):
                if ((count - 1) % 6 == 0):                                
                    #posWords=posFile.readline().strip().split()
                    key=line[1]+"_"+line[2]
                    print key
                    vCount=0
                    nCount=0
                    lemmaWords=self.testmap[key].split()
                    posWords=self.posmap[key].split()
                    depWordsList=self.testDepMap[key]
                    thisClass = self.getClassKey(maxLabel)
                    for word_pos in posWords:
                        spl=word_pos.split("_")
                        word_pos=word_pos.upper()
                        if word_pos not in self.posStopWords and spl[1][0]=="V":
                            vCount+=1
                        if word_pos not in self.posStopWords and spl[1][0]=="N":
                            nCount+=1                         
                    for word in lemmaWords:                       
                        #spl=word_pos.split("_")                       
                        #if word_pos.upper() not in stopWords and len(spl[0])>2 and pattern1.match(spl[0]):
                        if word not in stopWords and len(word)>1:#  and pattern1.match(word_pos):
                            wordCount += 1                                                             
                    sentPosition = line[2]
                    #resultFile.write(str(sentPosition) + "," + str(sentCount) + "," + heading + "\n")
                    #getWordFeaturesForLine
                    thisSentFeatures=[]
                    #adding bag of word featues
                    #for i in range(0,len(wordFeatures)):
                    #    thisSentFeatures.append('0') 
                    #    if wordFeatures[i] in lemmaWords:
                    #        thisSentFeatures[i]='1'
                    #adding unique word featues
                    for i in range(0,len(self.uniqueFeaturesList)):
                        thisSentFeatures.append('0')
                        if self.uniqueFeaturesList[i] in lemmaWords:
                            thisSentFeatures[i]='1'
                    index=len(thisSentFeatures)
                    # adding colocation features
                    for i in range(0,nfeature):
                        thisSentFeatures.append('0')
                        (word1,word2)=self.colList[i]
                        if word1 in lemmaWords and word2 in lemmaWords:
                            thisSentFeatures[index+i]='1'
                    #adding dependency features
                    
                    #sorted_full_map =sorted(self.fullDepMap.iteritems(), key=operator.itemgetter(1), reverse=True)
                    #mydepList=sorted_full_map[:500]
                    #index=len(thisSentFeatures)
                    #for i in range(0, nfeature):
                    #    thisSentFeatures.append('0')
                    #    (rel_w,score)=mydepList[i]
                    #    if rel_w in depWordsList:
                    #        thisSentFeatures[index+i]='1'
                    
                    
                    if sentPosition=="1":
                        if line[3].isupper():
                            structBool=True                            
                        else:
                            structBool=False
                            #print "StructBool FALSE", line[3]
                    if structBool and line[3].isupper():
                        heading = self.modifyHeading(line[3], "")
                        #thisSentFeatures=thisSentFeatures+[sentPosition + ","+str(wordCount),"4"]                                          
                        sentList.append(([str(prevClass)+","+str(vCount)+","+str(nCount)+","+sentPosition + ","+str(wordCount),"4"],thisSentFeatures))
                    elif structBool and not line[3].isupper():
                        #thisSentFeatures=thisSentFeatures+[sentPosition + ","+str(wordCount),heading]
                        sentList.append(([str(prevClass)+","+str(vCount)+","+str(nCount)+","+sentPosition + ","+str(wordCount),heading],thisSentFeatures))
                    elif not structBool:
                         #thisSentFeatures=thisSentFeatures+[sentPosition + ","+str(wordCount),""]
                         sentList.append(([str(prevClass)+","+str(vCount)+","+str(nCount)+","+sentPosition + ","+str(wordCount),""], thisSentFeatures))
        #print count,"no.of lines"
        if len(sentList)>0:
            indList=[]
            if not structBool:
                #print "Entered and Checking!"
                for i in range(1,5):                        
                    indList.append(math.ceil(float(len(sentList)*i/4)))
            for i in range(0,len(sentList)):
                (feaList,thisSentFeatures)=sentList[i]
                sentNorm=float(i+1)/len(sentList)
                revInd=len(sentList)-i 
                if not structBool:
                    heading=self.getDynamicHeading(i,indList,sentList)
                else:
                    heading=feaList[1]                                                                    
                resultFile.write(",".join(thisSentFeatures)+","+str(sentNorm)+","+str(revInd)+","+feaList[0]+","+heading+"\n")
                #resultFile.write(str(sentNorm)+","+sentList[i][0]+","+heading+"\n")        
        resultFile.close()
            
    
    def getClassKey(self, key):
        label="6"
        if (key=="population"): label = '1'
        if (key=="intervention"): label = '2'
        if (key=="background"): label = '3'
        if (key=="outcome"): label = '4'
        if (key=="study design"): label = '5'
        if (key=="other"): label = '6'   
        return label      
            
    def getFeaturesForLineTrain(self, stopWordFile,outFile,nfeature):
        pattern1=re.compile('[a-zA-Z]')
        wordFeatures=self.freqList[:nfeature]
        stopFile = open(stopWordFile)
        stopWords = [line.strip().upper() for line in stopFile.readlines()]
        stopFile.close()
        resultFile = open(outFile, 'w')        
        spamReader = csv.reader(open(self.trainfileName, 'rb'), delimiter=',')
        #posFile=open(self.trainPOSfile)
        count = 0
        heading = ""
        temp_heading=""
        sentList=[]
        fullsentList=[]
        structBool=False
        labels={}
        prevClass="6"
        thisClass="6"
        for line in spamReader:            
            count += 1
            resultText = ""
            wordCount = 0
            prevClass=thisClass
            if line[0]=="1":
                temp_heading=line[1]
                labels[line[1]]=1
                thisClass = self.getClassKey(line[1])
            if line[3]=="1" and len(sentList)>0:
                indList=[]
                if not structBool:
                    #print "Entered and Checking!"
                    for i in range(1,5):                        
                        indList.append(math.ceil(float(len(sentList)*i/4)))
                for i in range(0,len(sentList)):
                    (feaList,thisSentFeatures)=sentList[i]
                    sentNorm=float(i+1)/len(sentList)
                    revInd=len(sentList)-i 
                    if not structBool:
                        heading=self.getDynamicHeading(i,indList, sentList)
                    else:
                        heading=feaList[1]                                                                    
                    #resultFile.write(str(sentNorm)+","+str(revInd)+","+sentList[i][0]+","+heading+"\n")
                    myLabels=feaList[2]
                    for xlabel in myLabels:
                        resultFile.write(",".join(thisSentFeatures)+","+str(sentNorm)+","+str(revInd)+","+feaList[0]+","+heading+","+xlabel+"\n")
                    #resultFile.write(str(sentNorm)+","+sentList[i][0]+","+heading+"\n")
                sentList=[]                                   
            if (count > 1):
                if ((count - 1) % 6 == 0):
                    key=line[2]+"_"+line[3]
                    print key
                    vCount=0
                    nCount=0
                    lemmaWords=self.trainmap[key].split()                                   
                    posWords=self.posmap[key].split()
                    try:
                        depWordsList=self.trainDepMap[key]
                    except:
                        depWordsList=[]
                        pass
                    for word_pos in posWords:
                        spl=word_pos.split("_")
                        word_pos=word_pos.upper()
                        if word_pos not in self.posStopWords and spl[1][0]=="V":
                            vCount+=1
                        if word_pos not in self.posStopWords and spl[1][0]=="N":
                            nCount+=1                     
                    for word_pos in lemmaWords:                       
                        #spl=word_pos.split("_")                       
                        #if word_pos.upper() not in stopWords and len(spl[0])>2 and pattern1.match(spl[0]):
                        if word_pos not in stopWords and len(word_pos)>1: # and pattern1.match(word_pos):
                            wordCount += 1                                                             
                    sentPosition = line[3]
                    #resultFile.write(str(sentPosition) + "," + str(sentCount) + "," + heading + "\n")
                    
                    thisSentFeatures=[]
                    #adding bag of word lemma featues
                    #for i in range(0,len(wordFeatures)):
                    #    thisSentFeatures.append('0') 
                    #    if wordFeatures[i] in lemmaWords:
                    #        thisSentFeatures[i]='1'
                    #adding unique word featues
                    for i in range(0,len(self.uniqueFeaturesList)):
                        thisSentFeatures.append('0')
                        if self.uniqueFeaturesList[i] in lemmaWords:
                            thisSentFeatures[i]='1'
                    index=len(thisSentFeatures)
                    #adding collocation featues
                    for i in range(0,nfeature):
                        thisSentFeatures.append('0')
                        (word1,word2)=self.colList[i]
                        if word1 in lemmaWords and word2 in lemmaWords:
                            thisSentFeatures[index+i]='1'
                     #adding dependency features
                    #sorted_full_map =sorted(self.fullDepMap.iteritems(), key=operator.itemgetter(1), reverse=True)
                    #mydepList=sorted_full_map[:500]
                    #index=len(thisSentFeatures)
                    #for i in range(0, nfeature):
                    #    thisSentFeatures.append('0')
                    #    (rel_w,score)=mydepList[i]
                    #    if rel_w in depWordsList:
                    #        thisSentFeatures[index+i]='1'
                    if sentPosition=="1":
                        if line[4].isupper():
                            structBool=True                            
                        else:
                            structBool=False
                            #print "StructBool FALSE", line[4]                            
                    myLabels=[]
                    for key in labels.keys():
                        print key
                        label='5'
                        if (key=="population"): label = '1'
                        if (key=="intervention"): label = '2'
                        if (key=="background"): label = '3'
                        if (key=="outcome"): label = '4'
                        if (key=="study design"): label = '5'
                        if (key=="other"): label = '6' 
                        myLabels.append(label)       
                    if structBool and line[4].isupper():
                        heading = self.modifyHeading(line[4], "")
                        #thisSentFeatures=thisSentFeatures+[sentPosition + ","+str(wordCount),"4"]                                          
                        sentList.append(([str(prevClass)+","+str(vCount)+","+str(nCount)+","+sentPosition + ","+str(wordCount),"4", myLabels],thisSentFeatures))
                    elif structBool and not line[4].isupper():
                        #thisSentFeatures=thisSentFeatures+[sentPosition + ","+str(wordCount),heading]
                        sentList.append(([str(prevClass)+","+str(vCount)+","+str(nCount)+","+sentPosition + ","+str(wordCount),heading, myLabels],thisSentFeatures))
                    elif not structBool:
                        #thisSentFeatures=thisSentFeatures+[sentPosition + ","+str(wordCount),""]
                        sentList.append(([str(prevClass)+","+str(vCount)+","+str(nCount)+","+sentPosition + ","+str(wordCount),temp_heading, myLabels], thisSentFeatures))
                    labels={}
                          
        if len(sentList)>0:
            indList=[]
            if not structBool:
                #print "Entered and Checking!"
                for i in range(1,5):                        
                    indList.append(math.ceil(float(len(sentList)*i/4)))
            for i in range(0,len(sentList)):
                (feaList,thisSentFeatures)=sentList[i]
                sentNorm=float(i+1)/len(sentList)
                revInd=len(sentList)-i                
                if not structBool:
                    heading=self.getDynamicHeading(i,indList, sentList)
                else:
                    heading=feaList[1]
                myLabels=feaList[2]
                for xlabel in myLabels:                                                                    
                    resultFile.write(",".join(thisSentFeatures)+","+str(sentNorm)+","+str(revInd)+","+feaList[0]+","+heading+","+xlabel+"\n")
                #resultFile.write(str(sentNorm)+","+sentList[i][0]+","+heading+"\n")
        #posFile.close()
        resultFile.close()      
            
            
            
            
    def getDynamicHeading(self, index, indList,sentList):
        (feaList,testSentFeatures)=sentList[index]
        temp_heading=feaList[1]
        if temp_heading=="other":
            return "4"
        if temp_heading=="background":
            return "0"
        if temp_heading=="intervention" or temp_heading=="population" or temp_heading=="study design":
            return "1"
        if temp_heading=="outcome":
            return "2"
        if len(sentList)<=4:
            return str(index)
        if index<=indList[0]:
            return "0"
        if index<=indList[1]:
            return "1"
        if index<=indList[2]:
            return "2"
        if index<=indList[3]:
            return "3"
        
        
    
    def createPOSTrainfileFeatures(self, stopWordFile, outputFile):
        pattern1=re.compile('[a-zA-Z]')
        stopFile = open(stopWordFile)
        stopWords = [line.strip().upper() for line in stopFile.readlines()]
        stopFile.close()
        resultFile = open(outputFile, 'w')        
        spamReader = csv.reader(open(self.trainfileName, 'rb'), delimiter=',')
        posFile=open(self.trainPOSfile)
        count = 0
        heading = ""
        temp_heading=""
        sentList=[]
        structBool=False
        for line in spamReader:            
            count += 1
            resultText = ""
            wordCount = 0
            if line[0]=="1":
                temp_heading=line[1]
            if line[3]=="1" and len(sentList)>0:
                indList=[]
                if not structBool:
                    #print "Entered and Checking!"
                    for i in range(1,5):                        
                        indList.append(math.ceil(float(len(sentList)*i/4)))
                for i in range(0,len(sentList)):
                    sentNorm=float(i+1)/len(sentList)
                    revInd=len(sentList)-i 
                    if not structBool:
                        heading=self.getDynamicHeading(i,indList, sentList)
                    else:
                        heading=sentList[i][1]                                                                    
                    resultFile.write(str(sentNorm)+","+str(revInd)+","+sentList[i][0]+","+heading+"\n")
                    #resultFile.write(str(sentNorm)+","+sentList[i][0]+","+heading+"\n")
                sentList=[]                                   
            if (count > 1):
                if ((count - 1) % 6 == 0):                                
                    posWords=posFile.readline().strip().split()                     
                    for word_pos in posWords:                       
                        #spl=word_pos.split("_")                       
                        #if word_pos.upper() not in stopWords and len(spl[0])>2 and pattern1.match(spl[0]):
                        if word_pos not in stopWords and len(word_pos)>1 and pattern1.match(word_pos):
                            wordCount += 1                                                             
                    sentPosition = line[3]
                    #resultFile.write(str(sentPosition) + "," + str(sentCount) + "," + heading + "\n")
                    if sentPosition=="1":
                        if line[4].isupper():
                            structBool=True                            
                        else:
                            structBool=False
                            #print "StructBool FALSE", line[4]
                    if structBool and line[4].isupper():
                        heading = self.modifyHeading(line[4], "")                                            
                        sentList.append([sentPosition + ","+str(wordCount),"4"])
                    elif structBool and not line[4].isupper():
                        sentList.append([sentPosition + ","+str(wordCount),heading])
                    elif not structBool:
                         sentList.append([sentPosition + ","+str(wordCount),temp_heading])        
        if len(sentList)>0:
            indList=[]
            if not structBool:
                #print "Entered and Checking!"
                for i in range(1,5):                        
                    indList.append(math.ceil(float(len(sentList)*i/4)))
            for i in range(0,len(sentList)):
                sentNorm=float(i+1)/len(sentList)
                revInd=len(sentList)-i                
                if not structBool:
                    heading=self.getDynamicHeading(i,indList, sentList)
                else:
                    heading=sentList[i][1]                                                                    
                resultFile.write(str(sentNorm)+","+str(revInd)+","+sentList[i][0]+","+heading+"\n")
                #resultFile.write(str(sentNorm)+","+sentList[i][0]+","+heading+"\n")
        posFile.close()
        resultFile.close()
        
    def createPOSTestfileFeatures(self, stopWordFile, outputFile):
        pattern1=re.compile('[a-zA-Z]')
        stopFile = open(stopWordFile)
        stopWords = [line.strip().upper() for line in stopFile.readlines()]
        stopFile.close()
        resultFile = open(outputFile, 'w')        
        spamReader = csv.reader(open(self.testfileName, 'rb'), delimiter=',')
        posFile=open(self.testPOSfile)
        count = 0
        heading = ""
        sentList=[]
        structBool=False
        temp_heading=""
        for line in spamReader:            
            count += 1
            resultText = ""
            wordCount = 0          
            if line[2]=="1" and len(sentList)>0:
                #print line[3], structBool
                indList=[]
                if not structBool:
                    #print "Entered and checking!"
                    for i in range(1,5):
                        indList.append(math.ceil(float(len(sentList)*i/4)))
                for i in range(0,len(sentList)):
                    sentNorm=float(i+1)/len(sentList)
                    revInd=len(sentList)-i 
                    if not structBool:
                        heading=self.getDynamicHeading(i,indList,sentList)
                        #print heading
                    else:
                        heading=sentList[i][1]                                                                    
                    resultFile.write(str(sentNorm)+","+str(revInd)+","+sentList[i][0]+","+heading+"\n")
                    #resultFile.write(str(sentNorm)+","+sentList[i][0]+","+heading+"\n")
                sentList=[]                                   
            if (count > 1):
                if ((count - 1) % 6 == 0):                                
                    posWords=posFile.readline().strip().split()                     
                    for word_pos in posWords:                       
                        #spl=word_pos.split("_")                       
                        #if word_pos.upper() not in stopWords and len(spl[0])>2 and pattern1.match(spl[0]):
                        if word_pos not in stopWords and len(word_pos)>1  and pattern1.match(word_pos):
                            wordCount += 1                                                             
                    sentPosition = line[2]
                    #resultFile.write(str(sentPosition) + "," + str(sentCount) + "," + heading + "\n")
                    if sentPosition=="1":
                        if line[3].isupper():
                            structBool=True                            
                        else:
                            structBool=False
                            #print "StructBool FALSE", line[3]
                    if structBool and line[3].isupper():
                        heading = self.modifyHeading(line[3], "")                                            
                        sentList.append([sentPosition + ","+str(wordCount),"4"])
                    elif structBool and not line[3].isupper():
                        sentList.append([sentPosition + ","+str(wordCount),heading])
                    elif not structBool:
                         sentList.append([sentPosition + ","+str(wordCount),""])
        #print count,"no.of lines"
        if len(sentList)>0:
            indList=[]
            if not structBool:
                #print "Entered and Checking!"
                for i in range(1,5):                        
                    indList.append(math.ceil(float(len(sentList)*i/4)))
            for i in range(0,len(sentList)):
                sentNorm=float(i+1)/len(sentList)
                revInd=len(sentList)-i 
                if not structBool:
                    heading=self.getDynamicHeading(i,indList,sentList)
                else:
                    heading=sentList[i][1]                                                                    
                resultFile.write(str(sentNorm)+","+str(revInd)+","+sentList[i][0]+","+heading+"\n")
                #resultFile.write(str(sentNorm)+","+sentList[i][0]+","+heading+"\n")
        posFile.close()
        resultFile.close()
            
    def getDynamicHeadingOld(self, index, indList,sentList):
        temp_heading=sentList[index][1]
        if temp_heading=="other":
            return "4"
        if temp_heading=="background":
            return "0"
        if temp_heading=="intervention" or temp_heading=="population" or temp_heading=="study design":
            return "1"
        if temp_heading=="outcome":
            return "2"
        if len(sentList)<=4:
            return str(index)
        if index<=indList[0]:
            return "0"
        if index<=indList[1]:
            return "1"
        if index<=indList[2]:
            return "2"
        if index<=indList[3]:
            return "3"
            
    def modifyHeading(self, headingWord, temp_heading): 
        if temp_heading=="other":
            headingWord="4"
            return headingWord
        if headingWord.rfind("OBJECT")>=0 or headingWord.rfind("PRINCIPLE")>=0 or headingWord.rfind("RATIONALE")>=0 or headingWord.rfind("CONTEXT")>=0 or headingWord.rfind("ABSTRACT")>=0 or headingWord.rfind("QUESTION")>=0 or headingWord.rfind("BACKGROUND")>=0 or headingWord.rfind("AIM")>=0 or headingWord.rfind("PURPOSE") >=0 or headingWord.rfind("INTRODUCTION")>=0 or headingWord.rfind("INDICATION")>=0 or headingWord.rfind("CONTRADICTION")>=0:
            headingWord= "0" #self.headings[0]
        elif headingWord.rfind("DEVELOPMENT") >=0 or headingWord.rfind("PRESENTATION") >=0 or  headingWord.rfind("INTERVENTION") >=0 or headingWord.rfind("OPTION")>=0 or headingWord.rfind("VALUE")>=0 or headingWord.rfind("METHOD") >=0 or headingWord.rfind("PREDICTORS") >=0 or headingWord.rfind("FEATURE") >=0 or headingWord.rfind("POPULATION") >=0 or headingWord.rfind("SAMPLE") >=0 or headingWord.rfind("EXTRACTION") >=0 or headingWord.rfind("SOURCE") >=0 or headingWord.rfind("SELECTION") >=0 or headingWord.rfind("PARTICIPANT") >=0 or  headingWord.rfind("SETTING") >=0 or headingWord.rfind("DESIGN") >=0 or headingWord.rfind("SUBJECT") >=0 or headingWord.rfind("STRATEGY")>=0 or headingWord.rfind("CRITERIA")>=0 or headingWord.rfind("PATIENT")>=0:
           headingWord = "1" #self.headings[1]
        elif headingWord.rfind("MEASURE") >=0 or headingWord.rfind("RESULT") >=0  or  headingWord.rfind("LIMITATIONS")>=0 or headingWord.rfind("EVIDENCE") >=0 or headingWord.rfind("SIGNIFICANCE") >=0  or  headingWord.rfind("REPORT") >=0 or headingWord.rfind("SYNTHESIS")>=0 or headingWord.rfind("FINDING") >=0 or headingWord.rfind("OUTCOME") >=0 or headingWord.rfind("TECHNIQUE") >=0 or headingWord.rfind("ANALYSIS") >=0:
           headingWord = "2" #self.headings[2]
        elif headingWord.rfind("DISCUSSION")>=0  or headingWord.rfind("AUTHOR")>=0 or headingWord.rfind("REVIEW")>=0 or headingWord.rfind("SUMMARY")>=0 or headingWord.rfind("BENEFIT") >=0 or headingWord.rfind("ISSUE") >=0 or  headingWord.rfind("RECOMMENDATION")>=0 or headingWord.rfind("CONCLUSION")>=0 or headingWord.rfind("INTERPRETATION")>=0 or headingWord.rfind("IMPLICATIONS")>=0 or headingWord.rfind("RELEVANCE")>=0:
            headingWord = "3" #self.headings[3]
        else:
             print headingWord+"\n"        
        return headingWord
    
    def joinFeatures(self, fileInp1, fileInp2, outFile):
        file1=open(fileInp1)
        file2=open(fileInp2)
        file3=open(outFile,'w')
        line1=file1.readline().strip()
        while line1!="" and line1!=None:
            line2=file2.readline().strip()
            file3.write(line1+line2+"\n")
            #print line1+line2+"\n"
            line1=file1.readline().strip()
    #break
        file3.close()
        file1.close()
        file2.close()
    
